package com.sina.shop.controller.event;

import com.sina.shop.event.TestAsyncEvent;
import com.sina.shop.event.TestEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;

/**
 * Created with IntelliJ IDEA.
 * Description: 事件监听测试
 * 段浩杰   2018-01-08-11:37
 */
@Service("eventService")
public class EventService {

    private final Logger LOG = LoggerFactory.getLogger(this.getClass());


    @Autowired
    private ApplicationEventPublisher eventPublisher;

    public void testEvent() {
        Integer i;
        for (i = 0; i < 10; i++) {
            LOG.info("i:{}", i);
        }
        eventPublisher.publishEvent(new TestEvent(this, i));
    }

    public void testAsyncEvent() {
        Integer i;
        for (i = 0; i < 10; i++) {
            LOG.info("i:{}", i);
        }
        eventPublisher.publishEvent(new TestAsyncEvent(this, false, i));
    }
}
